home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 March: Reference Library / Dev.CD Mar 96 RL / Dev.CD Mar 96 RL.toast / Technical Documentation / develop / develop Issue 25 / develop Issue 25 code / Display Manager Sample / Source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-19  |  3.1 KB  |  163 lines  |  [TEXT/MPCC]

  1. /***********************************************************************
  2. #
  3. #        init.c
  4. #
  5. #        basic initialization code.
  6. #
  7. #        Author: Michael Marinkovich
  8. #                Apple Developer Technical Support
  9. #
  10. #
  11. #        Modification History: 
  12. #
  13. #            6/4/95        MWM     Initial coding                     
  14. #            10/12/95    MWM        cleaned up
  15. #
  16. #        Copyright © 1992-95 Apple Computer, Inc., All Rights Reserved
  17. #
  18. #
  19. ***********************************************************************/
  20.  
  21.  
  22. #include <AppleEvents.h>
  23. #include <Displays.h>
  24. #include <Events.h>
  25. #include <Fonts.h>
  26. #include <Gestalt.h>
  27. #include <Menus.h>
  28. #include <OSUtils.h>
  29.  
  30. #include "App.h"
  31. #include "Proto.h"
  32.  
  33. extern Boolean             gHasDMTwo;
  34. extern Boolean             gHasDrag;
  35. extern Boolean            gInBackground;
  36. extern short            gWindCount;
  37.  
  38.  
  39. //----------------------------------------------------------------------
  40. //
  41. //    Initialize - the main entry point for the initialization
  42. //
  43. //
  44. //----------------------------------------------------------------------
  45.  
  46. OSErr Initialize(void)
  47. {
  48.     OSErr        err = noErr;
  49.     
  50.     
  51.     ToolBoxInit();
  52.     CheckEnvironment();
  53.     err = InitApp();
  54.     
  55.     return err;
  56. }
  57.  
  58.  
  59. //----------------------------------------------------------------------
  60. //
  61. //    ToolBoxInit - initialization all the needed managers
  62. //
  63. //
  64. //----------------------------------------------------------------------
  65.  
  66. void ToolBoxInit(void)
  67. {
  68.  
  69.     InitGraf(&qd.thePort);
  70.     InitFonts();
  71.     InitWindows();
  72.     InitMenus();
  73.     TEInit();
  74.     InitDialogs(nil);
  75.     InitCursor();
  76.         
  77.     FlushEvents(everyEvent, 0);
  78.  
  79. }
  80.  
  81.  
  82. //----------------------------------------------------------------------
  83. //
  84. //    CheckEnvironment - make sure we can run with current sys and managers.
  85. //                       Also initialize globals - have drag & drop
  86. //                      
  87. //----------------------------------------------------------------------
  88.  
  89. void CheckEnvironment(void)
  90. {
  91.     OSErr            err;
  92.     long            response;
  93.     
  94.  
  95.     // check to see if the Display Manager is present. If it is 
  96.     // then we have a PowerMac or System 7.5.
  97.     err = Gestalt(gestaltDisplayMgrAttr, &response);
  98.     
  99.     if (err != noErr || ((response & (1 << gestaltDisplayMgrPresent)) == 0))
  100.          HandleAlert(kNeedsDisplayManager);
  101.     
  102.     // check for Display Manager 2.0
  103.     else {
  104.         Gestalt(gestaltDisplayMgrVers, (long*)&response);
  105.         gHasDMTwo = (response >= 0x00020000);
  106.     }
  107.  
  108. }
  109.  
  110.  
  111. //----------------------------------------------------------------------
  112. //
  113. //    InitApp - initialization all the application specific stuff
  114. //
  115. //
  116. //----------------------------------------------------------------------
  117.  
  118. OSErr InitApp(void)
  119. {
  120.     OSErr                err;
  121.  
  122.     // init AppleEvents
  123.     err = AEInit();
  124.     MenuSetup();
  125.  
  126.     // we have DM 2.0 so install
  127.     // world changed notification proc
  128.     if (gHasDMTwo)
  129.         err = InstallDMNotification();
  130.  
  131.     // we have DM 1.0 so install AppleEvent Notification
  132.     else
  133.         err = InstallAEDMNotification();
  134.  
  135.     // init any globals
  136.     gWindCount = 1;
  137.  
  138.     return err;                    
  139. }
  140.  
  141.  
  142. //----------------------------------------------------------------------
  143. //
  144. //    MenuSetup - 
  145. //
  146. //
  147. //----------------------------------------------------------------------
  148.  
  149. void MenuSetup(void)
  150. {
  151.     Handle            menu;
  152.         
  153.         
  154.     menu = GetNewMBar(rMBarID);        //    get our menus from resource
  155.     SetMenuBar(menu);
  156.     DisposeHandle(menu);
  157.     AddResMenu(GetMHandle(mApple ), 'DRVR');        //    add apple menu items
  158.  
  159.     DrawMenuBar();
  160.  
  161.         
  162. }
  163.